﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data.SqlClient;
using System.Data;


namespace Web.Admin.Report
{
    public partial class RWBExchangeDetail : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DataBind();
            }
        }
        private void DataBind()
        {

            //获取存粮信息
            StringBuilder strSql = new StringBuilder();
            strSql.Append("  SELECT F.ID as Dep_ID,F.strName as Dep_Name, W.ID as WBID, W.strName as WBName, B.ID as TradeWBID, B.strName AS TradeWBName, D.strName AS  VarietyName, E.strName AS  GoodName, GoodCount,VarietyCount,");
            strSql.Append("   Money_DuiHuan,VarietyInterest");
            strSql.Append("  FROM dbo.GoodExchange A INNER JOIN dbo.WB B ON A.WBID=B.ID");
            strSql.Append("  INNER JOIN dbo.Dep_StorageInfo C ON A.Dep_SID=C.ID");
            strSql.Append("   INNER JOIN dbo.StorageVariety D ON C.VarietyID=D.ID");
            strSql.Append("  INNER JOIN dbo.Good E ON A.GoodID=E.ID");
            strSql.Append("   INNER JOIN dbo.Depositor F ON A.Dep_AccountNumber=F.AccountNumber");
            strSql.Append("   INNER JOIN dbo.WB W ON F.WBID=W.ID");
            strSql.Append("  ");
            strSql.Append("  where 1=1 and B.ISSimulate=0");

            if (Request.QueryString["TradeWBID"] != null && Request.QueryString["TradeWBID"].ToString() != "")
            {
                strSql.Append("   AND B.ID = " + Request.QueryString["TradeWBID"].ToString());
            }
            if (Request.QueryString["WBID"] != null && Request.QueryString["WBID"].ToString() != "")
            {
                strSql.Append("   AND W.ID = " + Request.QueryString["WBID"].ToString());
            }
            if (Request.QueryString["GoodID"] != null && Request.QueryString["GoodID"].ToString() != "")
            {
                strSql.Append("   AND E.ID = " + Request.QueryString["GoodID"].ToString());
            }
            if (Request.QueryString["VarietyID"] != null && Request.QueryString["VarietyID"].ToString() != "")
            {
                strSql.Append("   AND D.ID = " + Request.QueryString["VarietyID"].ToString());
            }

            if (Request.QueryString["dtBegin"] != null && Request.QueryString["dtBegin"].ToString() != "")
            {
                strSql.Append("   AND A.dt_Exchange> '" + Request.QueryString["dtBegin"].ToString() + "'");

            }
            if (Request.QueryString["dtEnd"] != null && Request.QueryString["dtEnd"].ToString() != "")
            {
                strSql.Append("   AND A.dt_Exchange < '" + Request.QueryString["dtEnd"].ToString() + "'");
            }


            DataTable dt = SQLHelper.ExecuteDataTable(strSql.ToString());
          
            Repeater1.DataSource = dt;
            Repeater1.DataBind();



        }



        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {

            DataBind();

        }
    }
}